import { GButton } from "../../../../com/mui/controls/GButton";
import { SecTimer } from "../../../../com/gengine/core/frame/SecTimer";
import { TimerType } from "../../../../com/gengine/core/frame/TimerType";
type int = number;
//class SecTimerButton
    
    export  class SecTimerButton extends GButton
    {
        constructor()
        {
            super();
            return;
        }

        public /* override */ set label(arg1: string)
        {
            super.label = arg1;
            this._labelStr = arg1;
            return;
        }

        public startCountdown(arg1: int, arg2: Function=null, arg3: Boolean=true): void
        {
            if (this._secTimer != null) 
            {
                this._secTimer.reset();
            }
            else 
            {
                this._secTimer = new SecTimer();
                this._secTimer.addListener(TimerType.COMPLETE, this.onTimerCompleteHandler);
                this._secTimer.addListener(TimerType.ENTERFRAME, this.onEnterFrameHandler);
            }
            this._secTimer.repeatCount = arg1;
            if (arg3) 
            {
                this._secTimer.start();
            }
            return;
        }

        public reset(): void
        {
            if (this._secTimer) 
            {
                this._secTimer.reset();
                this._secTimer.repeatCount = 0;
            }
            if (this._labelStr != null) 
            {
                super.label = this._labelStr;
            }
            return;
        }

        public stop(): void
        {
            if (this._secTimer) 
            {
                return this._secTimer.stop();
            }
            if (this._labelStr != null) 
            {
                super.label = this._labelStr;
            }
            return;
        }

        public get running(): Boolean
        {
            if (this._secTimer) 
            {
                return this._secTimer.running;
            }
            return false;
        }

        public set timeOutHandler(arg1: Function)
        {
            this._callback = arg1;
            return;
        }

        /* internal  */onTimerCompleteHandler(arg1: SecTimer): void
        {
            if (this._callback != null) 
            {
                this._callback.apply();
            }
            this.stop();
            return;
        }

        /* internal  */onEnterFrameHandler(arg1: SecTimer): void
        {
            super.label = this._labelStr + "(" + arg1.repeatCount + ")";
            if (arg1.repeatCount <= 0 && !(this._labelStr == null)) 
            {
                super.label = this._labelStr;
            }
            return;
        }

        /* internal */ /* var */_secTimer: SecTimer;

        /* internal */ /* var */_callback: Function;

        /* internal */ /* var */_labelStr: string;
    }
